package com.example.linyiquan.login.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.linyiquan.login.R;
import com.example.linyiquan.login.bean.AppBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by linyiquan on 17-4-14.
 */

public class GridAdapter extends BaseAdapter{
    List<AppBean> items = new ArrayList<>();

    public GridAdapter(Context context,List<AppBean> items) {
        this.items = items;
        this.items.add(new AppBean("Add",
                context.getResources().getDrawable(R.drawable.button)
                ,""));
        this.items.add(new AppBean("Remove",
                context.getResources().getDrawable(R.drawable.button)
                ,""));

    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public AppBean getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AppBean item = items.get(position);
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.grid_img);
        TextView title = (TextView) view.findViewById(R.id.grid_tv);
        imageView.setImageDrawable(item.getIcon());
        title.setText(item.getAppName());
        return view;
    }
}
